﻿#ifndef CIsapiServer_H
#define CIsapiServer_H
/********************************************************************************
** @ Date:2025/01/15
** @ Author: HanJiaXin
** @ Description:ISAPI服务端(http服务)
** @ Version:1.0.0
** @ ClassName:CIsapiServer
** @ Fun:
********************************************************************************/
#include <QObject>
#include <QTcpServer>
#include <QTimer>

class CIsapiServer  : public QTcpServer
{
	Q_OBJECT

public:
	explicit CIsapiServer();
	~CIsapiServer();

	void setNetworkParameter(QString sIp, int nPort);//设置网络参数 ip:监听网址 port监听端口号
	bool startServer(QString &sErrMsg);//开启服务器监听

protected:
	void incomingConnection(qintptr socketDescriptor) override;

private:
	bool isRequestComplete(const QByteArray &requestData);
	void processCompleteRequest(QTcpSocket *socket);
	void cleanupConnection(QTcpSocket *socket);

private slots:
	void onReadyRead();//新的请求到达
	void onDisconnected();
	void onRequestTimeout();

signals:
	void sigNewRequest(QByteArray &requestData);

private:
	int m_nPort;//监听端口号
	QString m_sIp;//监听IP地址
	QHash<QTcpSocket*, QByteArray> m_requestBuffers;
	QHash<QTcpSocket*, QTimer*> m_requestTimers;
};

#endif